function showMessage(_text, _type, _timeout, _btn) {
    if(!_text) {
        return;
    }
    if(!_type) {
        // success, info, warning, error
        _type = 'info';
    }
    if(!_timeout) {
        _timeout = 3000; // milliseconds
    }
    if(!_btn) {
        _btn = true;
    }
    else {
        _btn = !!_btn;
    }
    // https://www.tinymce.com/docs/advanced/creating-custom-notifications/
    tinymce.activeEditor.notificationManager.open({
        text: _text,
        type: _type,
        timeout: _timeout,
        closeButton: _btn
    });
}

tinymce.init({
    selector: '#article-editor',
    schema: 'html5',
    theme: 'modern',
    skin: 'lightgray',
    height: 300,
    content_style: 'h1 {font-size: 32px; color: #0089ee}',
    min_height: 100,
    min_width: 100,
    autoresize_min_height: (window.innerHeight || document.documentElement.clientHeight) - 20,
    langeage: 'zh_CN',
    language_url: GLOBAL.TINYMCE_LANG_zh_CN,
    inline: false,
    resize: true,
    autosave_ask_before_unload: true,
    elementpath: true,
    menubar: false, // 菜单栏
    statusbar: true,
    powerpaste_allow_local_images: false,
    plugins: [
        'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker',
        'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
        'save table contextmenu directionality emoticons template paste textcolor',
        // 'imagetools',
        'fullpage colorpicker codesample autoresize'
    ],
    external_plugins: {},
    // code_dialog_height: 300,
    // code_dialog_width: 350,
    advlist_bullet_styles: 'square',
    advlist_number_styles: 'lower-alpha,lower-roman,upper-alpha,upper-roman',
    toolbar: [
        'undo redo searchreplace',
        'formatselect fontselect fontsizeselect', //styleselect
        'bold italic underline strikethrough subscript superscript hr removeformat pagebreak',
        'alignleft aligncenter alignright alignjustify',
        'bullist numlist outdent indent',
        'charmap insertdatetime link media template',
        'forecolor backcolor emoticons',
        'codesample code preview print restoredraft',
        'mySave image'
    ].join(' | '),
    image_advtab: true,
    imagetools_toolbar: "rotateleft rotateright | flipv fliph | editimage imageoptions",
    images_upload_url: '/courseware/upload/',
    content_save_url: '/admin/help_save/',
    imagetools_proxy: '/admin/help_catalog/',
    paste_data_images: true,
    images_upload_handler: function(blobInfo, success, failure) {
        success("data:" + blobInfo.blob().type + ";base64," + blobInfo.base64());
    },
    file_browser_callback: function(field_name, url, type, win) {
        if(type=='image') {
            $(document.body).data("help-image-target",field_name);
            $('#my_form input').click();
        }
    },
    automatic_uploads: false,
    convert_urls: false,
    force_p_newlines: true,
    remove_trailing_brs: false,
    forced_root_block_attrs: {
        'class': 'myclass',
        'data-something': 'my data'
    },
    templates: [
        {
            title: 'Test template 1',
            content: 'Test 1'
        }, {
            title: 'Test template 2',
            content: 'Test 2'
        }
    ],
    setup: function (editor) {
        /*
        $('#content-editor').data('editor-instance', editor);
        editor.addCommand('my_mceSave', function() {
            // https://www.tinymce.com/docs/api/class/tinymce.editor/#getcontent
            var _content = editor.getBody().innerHTML;
            var _url = editor.getParam('content_save_url', null);
            var _id = $('#left-nav-tree .left-nav-body .nav-tree-box div[data-id].current-item').attr('data-id');
            if(_content && _url && _id) {
                if(_id == TREE_ROOT_CATALOG) {
                    editor.setContent('目录');
                    editor.save();
                    editor.setDirty(!1);
                    editor.fire('dirty');
                    showMessage('目录是自动生成的节点，不支持保存', 'info');
                }
                else {
                    $.ajax({
                        url: _url,
                        type: 'POST',
                        data: {
                            content: _content,
                            id: _id
                        },
                        dataType: 'json',
                        success: function(data) {
                            var _type = 'error'; // success, info, warning, error
                            if(data.error == 0) {
                                $(document.body).data('data-content')[_id] = _content;
                                editor.save();
                                editor.setDirty(!1);
                                editor.fire('dirty');
                                _type = 'success';
                            }
                            showMessage(data.desc, _type);
                        },
                        error: function(data) {
                            try {
                                console.log(data);
                            }
                            catch (ex) {}
                        }
                    });
                }
            }
            else {
                showMessage('has error', 'error');
            }
        });
        editor.addButton('mySave', {
            text: 'Save',
            icon: 'save',
            cmd: 'my_mceSave',
            disabled: !0,
            onPostRender: function() {
                var self = this;
                editor.on('nodeChange dirty', function () {
                    self.disabled(editor.getParam('save_enablewhendirty', !0) && !editor.isDirty());
                    if(!editor.isDirty()) {
                        self.active(false);
                    }
                })
            }
        });
        */
    },
    init_instance_callback : function(editor) {
        // showOneItem(true);
    }
});